<?php

namespace app\backend\controller;
use app\backend\service\ConvertService;

class Convert extends Backend
{
    /**
     * 套餐列表
     * @param ConvertService $service
     * @return string|\think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index(ConvertService $service)
    {
        if ($this->request->isAjax()) {
            return $this->success($service->lists($this->request->param()));
        }
        return $this->fetch('', $service->convertLabel());
    }

    /**
     * 添加套餐
     * @param ConvertService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function add(ConvertService $service)
    {
        if ($this->request->isAjax()) {
            $addResult = $service->add($this->request->param());
            return $this->success($addResult);
        }
        return $this->fetch('', $service->convertLabel());
    }

    /**
     * 添加套餐
     * @param ConvertService $service
     * @return string|\think\response\Json
     * @throws \app\common\RootException
     */
    public function edit(ConvertService $service)
    {
        $params = $this->request->param();
        if ($this->request->isAjax()) {
            $renewResult = $service->edit($params);
            return $this->success($renewResult);
        }
        $fetchData = $service->convertLabel();
        $fetchData['info'] = $service->detail($params['id']);
        return $this->fetch('', $fetchData);
    }

    /**
     * 套餐详情
     * @param ConvertService $service
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail(ConvertService $service)
    {
        $fetchData = $service->convertLabel();
        $fetchData['info'] = $service->detail($this->request->param('id'));
        return $this->fetch('', $fetchData);
    }

    /**
     * 删除套餐
     * @param ConvertService $service
     * @return \think\response\Json
     * @throws \app\common\RootException
     */
    public function del(ConvertService $service)
    {
        $delRst = $this->request->param('id');
        return $this->success($service->del($delRst));
    }
}